﻿#region Header

// Majesty of Omega - The next evolution of macro management space strategy
// 
// Copyright 2007-2009 André Claaßen
// 
// This file is protected by the terms and conditions of the
// Microsoft Community License (Ms-CL 1.1), a copy of which should
// have been distributed along with this software. If not,
// you may find the license information at the following URL:
// 
// http://www.microsoft.com/resources/sharedsource/licensingbasics/communitylicense.mspx

#endregion

#region

using System;
using System.Collections.Generic;
using System.Windows.Data;
using Majesty_of_Omega.Logic.Calculate;
using Majesty_of_Omega.Logic.GameConfiguration;
using Majesty_of_Omega.Model.Research;
using Majesty_of_Omega.Model.Space;
using Majesty_of_Omega.Model.Game;
using Majesty_of_Omega.Model.Report;
using Majesty_of_Omega.Config;
using Majesty_of_Omega.Model.Structures;

#endregion

namespace Majesty_of_Omega.Logic.Generator
{
    /// <summary>
    /// Test data generator for unit tests or WPF editing purposes with expression blend
    /// </summary>
    public class TestDataGenerator
    {
        /// <summary>
        /// Number of generated test games. The TestDataGenerator ensures, that the number of test games
        /// is equal to this constant.
        /// </summary>
        public const int NumberOfTestGames = 5;

        /// <summary>
        /// The <see cref="ObjectDataProvider"/> needs a property
        /// </summary>
        public Region TestRegion
        {
            get { return CreateTestRegion(RegionType.Broken); }
        }

        /// <summary>
        /// This property generates a save game for testing purposes. The SitReport can be used
        /// for data binding with Expression Blend.
        /// </summary>
        public static SaveGame TestSaveGame
        {
            get
            {
                var gameGenerator = new GameGenerator(CreateTestGameSettings());
                SaveGame game = gameGenerator.GenerateNewGame();
                game.HumanPlayer.ResearchManager.TotalResearchPointsOfCurrentTurn = 500;
                return game;
            }
        }

        /// <summary>
        /// Gets a test <see cref="SaveGameManager.SaveGameInfo" />.
        /// </summary>
        /// <value>The test save game info.</value>
        public static SaveGameManager.SaveGameInfo TestSaveGameInfo
        {
            get
            {
                return new SaveGameManager.SaveGameInfo
                           {
                               GameName = "Testgame",
                               RaceName = "Humans",
                               SaveGameNumber = 1,
                               Time = DateTime.Now,
                               TurnNumber = 471
                           };
            }
        }

        /// <summary>
        /// Gets the test game manager with 15 Test games saved
        /// </summary>
        /// <value>The test game manager.</value>
        /// <remarks>
        /// This SitReport is for editing purposes in expression blend with some 
        /// optimizations.
        /// </remarks>
        public static SaveGameManager testSaveGameManager
        {
            get
            {
                var gameManager = new SaveGameManager(true);
                List<SaveGameManager.SaveGameInfo> lastGames = gameManager.LastGamesInMooGameFolder;
                if (lastGames.Count == NumberOfTestGames) return gameManager;

                gameManager.EraseAllGamesInMooGameFolder();
                for (int i = 0; i < NumberOfTestGames; i++)
                    gameManager.Save(TestSaveGame, string.Format("Test Game {0}", i.ToString("D2")));
                return gameManager;
            }
        }

        /// <summary>
        /// Gets the tech fields for the first techschool
        /// </summary>
        /// <remarks>
        /// This property exists for editing purposes in blend for the research.xaml page
        /// </remarks>
        /// <returns></returns>
        public List<TechField> TestTechFields
        {
            get
            {
                return SpreadSheetManager.TechTables.TechSchools[0].TechFields;
            }
        }

        /// <summary>
        /// Gets the test galaxy.
        /// </summary>
        /// <remarks>
        /// This property exists for editing purposes in blend for the research.xaml page
        /// </remarks>
        /// <value>The test galaxy.</value>
        public StarGalaxy TestGalaxy
        {
            get
            {
                return TestSaveGame.Galaxy;
            }
        }

        /// <summary>
        /// Creates a test region for wpf development with Expression Blend
        /// </summary>
        /// <returns></returns>
        public static Region CreateTestRegion(RegionType regionType)
        {
            var region = new Region(new Planet(new Star("Test star for the region")))
                             {
                                 BioDiversity = RegionBioDiversity.Similar,
                                 RegionType = regionType
                             };
            DEA deaRegional = region.DeaList[0];
            deaRegional.Improvements.Add(new Improvement("Sanitary Complex"));
            var deaFarm = new DEA(region, DeaType.DeaFarm);
            region.DeaList.Add(deaFarm);
            deaFarm.Improvements.Add(new Improvement("Biological Complex"));
            region.DeaList.Add(new DEA(region, DeaType.DeaIndustry));
            region.DeaList.Add(new DEA(region, DeaType.DeaSpacePort));
            return region;
        }

        /// <summary>
        /// Create reliable game settings for the 2 - Arms Galaxy Configuration out of the GalaxyConfiguration.xaml file
        /// </summary>
        /// <returns>GameSettings</returns>
        public static GameSettings CreateTestGameSettings()
        {
            return new GameSettings
                       {
                           GalaxyConfigurationByName = "2 - Arms Galaxy"
                       };
        }

        /// <summary>
        /// Creates a test game with some researched technologies
        /// </summary>
        /// <param name="distributableTechPoints">The distributable tech points.</param>
        /// <returns></returns>
        public static SaveGame CreateTestGameWithSomeResearchedTechs(int distributableTechPoints)
        {
            var saveGame = TestSaveGame;
            var nextTurnCalculator = new NextTurnCalculator(saveGame);
            saveGame.HumanPlayer.ResearchManager.TotalResearchPointsOfCurrentTurn = distributableTechPoints;
            nextTurnCalculator.CalculateNextTurn();
            return saveGame;
        }

        /// <summary>
        /// Generates a test Situation SitReport
        /// </summary>
        /// <returns></returns>
        public SitReport GetTestSitReport()
        {
            var sitReport = new SitReport();
            var turn1 = new SitReportTurn { TurnNumber = 1 };
            sitReport.AddSitReportTurn(turn1);

            turn1.SitReportEntries.Add(new SitReportEntry
                                           {
                                               Icon = "PDefence.png",
                                               ReportPriority = SitReportPriority.Green,
                                               Description = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. Nunc viverra imperdiet enim. Fusce est.",
                                           });
            turn1.SitReportEntries.Add(new SitReportEntry
                                           {
                                               Icon = "PDefence.png",
                                               ReportPriority = SitReportPriority.Yellow,
                                               Description = "Vivamus a tellus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin pharetra nonummy pede. Mauris et orci. Aenean nec lorem.",
                                           });
            turn1.SitReportEntries.Add(new SitReportEntry
                                           {
                                               Icon = "PDefence.png",
                                               ReportPriority = SitReportPriority.Red,
                                               Description = "Red In porttitor. Donec laoreet nonummy augue. Suspendisse dui purus, scelerisque at, vulputate vitae, pretium mattis, nunc. Mauris eget neque at sem venenatis eleifend. Ut nonummy.",
                                           });
            turn1.SitReportEntries.Add(new SitReportEntry
                                           {
                                               Icon = "PDefence.png",
                                               ReportPriority = SitReportPriority.Green,
                                               Description = "Fusce aliquet pede non pede. Suspendisse dapibus lorem pellentesque magna. Integer nulla. Donec blandit feugiat ligula. Donec hendrerit, felis et imperdiet euismod, purus ipsum pretium metus, in lacinia nulla nisl eget sapien."
                                           });

            var turn2 = new SitReportTurn { TurnNumber = 2 };
            sitReport.AddSitReportTurn(turn2);
            turn2.SitReportEntries.Add(new SitReportEntry
                                           {
                                               Icon = "Governmental.png",
                                               ReportPriority = SitReportPriority.Green,
                                               Description = "Maecenas odio dolor, vulputate vel, auctor ac, accumsan id, felis. Pellentesque cursus sagittis felis. Pellentesque porttitor, velit lacinia egestas auctor, diam eros tempus arcu, nec vulputate augue magna vel risus. Cras non magna vel ante adipiscing rhoncus. Vivamus a mi. Morbi neque. Aliquam erat volutpat. ",
                                           });
            turn2.SitReportEntries.Add(new SitReportEntry
                                           {
                                               Icon = "SpaceLanes.png",
                                               ReportPriority = SitReportPriority.Green,
                                               Description = "Aliquam nonummy adipiscing augue. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus.",
                                           });
            return sitReport;
        }


    }
}